package com.jk.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.jk.dao.TbStudentMapper;
import com.jk.dto.TbStudent;
import com.jk.pojo.PagedResponse;
import com.jk.service.TbStudentService;
import com.jk.utils.PaginationUtil;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author yzf
 * @version 1.0
 * @description: TODO
 * @date 2024/12/9 19:24
 */
@Service
public class TbStudentServiceImpl implements TbStudentService {

    @Autowired
    private TbStudentMapper tbStudentMapper;
    @Override
    public PagedResponse<TbStudent> findTbStudentList(TbStudent tbStudent, Integer pageNum, Integer pageSize) {
        Page<TbStudent> page = new Page<>(pageNum, pageSize);
        QueryWrapper<TbStudent> query = new QueryWrapper<>();
        Page<TbStudent> studentPage = tbStudentMapper.selectPage(page, query);
        return PaginationUtil.getPagedResponse(studentPage.getRecords(),pageNum,pageSize,studentPage.getTotal());
    }

    @Override
    public void addStudent(TbStudent tbStudent) {
        tbStudentMapper.insert(tbStudent);
    }

    @Override
    public TbStudent findStudentByUserName(String username) {
        QueryWrapper<TbStudent> query = new QueryWrapper<>();
        query.eq("user_name", username);
        return tbStudentMapper.selectOne(query);
    }

    @Override
    public void deleteStudentById(Integer id) {
        tbStudentMapper.deleteById(id);
    }

    @Override
    public TbStudent getStudentById(Integer id) {
        return tbStudentMapper.selectById(id);
    }

    @Override
    public void upStudent(TbStudent tbStudent) {
        tbStudentMapper.updateById(tbStudent);
    }

    @Override
    public void upstatus(TbStudent tbStudent) {
        tbStudentMapper.upstatus(tbStudent);
    }

    @Override
    public void updatestatus(TbStudent tbStudent) {
        tbStudentMapper.updatestatus(tbStudent);

    }

    @Override
    public List<TbStudent> findTbStudent() {
        return tbStudentMapper.selectList(null);
    }
}
